<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .progress{
            position: fixed;
            top: 0px;
            left: 0px;
            width: 0%;
            height: 6px;
            background-color: #409eff;
            box-shadow: 0 0 8px #409eff;
            transition: all ease 400ms;
        }
    </style>
    <script>
        (function(){
            let progressDom = null;
            let count = 0;
            let size = 30;
            let timer = null;
            function createProgress(){
                let divDom = document.createElement("div");
                divDom.className = "progress";
                divDom.style.width = "0%";
                return divDom;
            }

            window.progress = {
                start:function(){
                    count++;
                    if(!progressDom){
                        progressDom = createProgress();
                        document.body.appendChild(progressDom);
                        setTimeout(function(){
                            progressDom.style.width = size+"%";
                        },10)
                        timer = setInterval(function(){
                            size = (100-size)/50 + size;
                            progressDom.style.width = size + "%"
                        },400)
                    }
                },
                done:function(){
                    if(count<=0){
                        return;
                    }
                    count--
                    if(count<=0){
                        clearInterval(timer);
                        timer = null;
                        size = 30;
                        progressDom.ontransitionend = function(){
                            document.body.removeChild(progressDom);
                            progressDom = null;
                        }
                        progressDom.style.width = "100%";
                    }
                }
            }
        })()

    </script>
</head>
<body>
    <!-- <div class="progress"></div> -->
    <input type="button" value="open" onclick="progress.start()">
    <input type="button" value="close" onclick="progress.done()">

</body>
</html>